package widget;

import java.awt.Font;
import org.netbeans.api.visual.border.Border;
import org.netbeans.api.visual.border.BorderFactory;
import org.netbeans.api.visual.layout.LayoutFactory;
import org.netbeans.api.visual.widget.LabelWidget;
import org.netbeans.api.visual.widget.Scene;
import org.netbeans.api.visual.widget.Widget;

/**
 * @author Durval Slompo Junior
 */
public class EntidadeWidget extends Widget {
    
    //Members of component
    private LabelWidget nomeDaEntidade;
    private Widget entidade;
    private Widget pks;
    private Widget others;
    
    private static final Border BORDER_FOUR = BorderFactory.createLineBorder(4);

    public EntidadeWidget(Scene scene, String node) {
        super(scene);
        setLayout(LayoutFactory.createVerticalFlowLayout());
        setOpaque(true);
        setCheckClipping(true);
        
        Widget entidadeWithName = new Widget(scene);
        entidadeWithName.setLayout(LayoutFactory.createVerticalFlowLayout());
        
        nomeDaEntidade = new LabelWidget(scene);
        nomeDaEntidade.setLabel(node);
        nomeDaEntidade.setFont(scene.getDefaultFont().deriveFont(Font.BOLD));
        entidadeWithName.addChild(nomeDaEntidade);
        
        entidade = new Widget(scene);
        entidade.setLayout(LayoutFactory.createHorizontalFlowLayout());
        
        pks = new Widget(scene);
        pks.setLayout(LayoutFactory.createVerticalFlowLayout());
        pks.setOpaque(false);
        pks.setBorder(BORDER_FOUR);
        entidadeWithName.addChild(pks);
        
        others = new Widget(scene);
        others.setLayout(LayoutFactory.createVerticalFlowLayout());
        others.setOpaque(false);
        others.setBorder(BORDER_FOUR);
        entidadeWithName.addChild(others);
        
        addChild(entidadeWithName);
    }
    
    public Widget createPK(String pkName){
        Scene scene = getScene();
        Widget w = new Widget(scene);
        w.setLayout(LayoutFactory.createHorizontalFlowLayout());
        
        LabelWidget lw = new LabelWidget(scene, pkName);
        w.addChild(lw);
        
        LabelWidget lwPK = new LabelWidget(scene, "   PK");
        w.addChild(lwPK);
        
        return w;
    }
    
    public Widget createFK(String fkName){
        Scene scene = getScene();
        Widget w = new Widget(scene);
        w.setLayout(LayoutFactory.createHorizontalFlowLayout());
        
        LabelWidget lw = new LabelWidget(scene, fkName);
        w.addChild(lw);
        
        LabelWidget lwFK = new LabelWidget(scene, "   FK");
        w.addChild(lwFK);
        
        return w;
    }
    
    public Widget createOther(String otherName){
        Scene scene = getScene();
        Widget w = new Widget(scene);
        w.setLayout(LayoutFactory.createHorizontalFlowLayout());
        
        LabelWidget lw = new LabelWidget(scene, otherName);
        w.addChild(lw);
        
        return w;
    }

    public String getNomeEntidade() {
        return nomeDaEntidade.getLabel();
    }
    
    public void setNomeEntidade(String nome){
        nomeDaEntidade.setLabel(nome);
    }
    
    public void addPK(Widget w){
        pks.addChild(w);
    }
    
    public void removePK(Widget w){
        pks.removeChild(w);
    }
    
    public void addOther(Widget w){
        others.addChild(w);
    }
    
    public void removeOther(Widget w){
        others.removeChild(w);
    }
    
}
